<?php
# $Id$
require_once(APP_LIB_DIR . 'Sajax.php');
require_once('utils.inc.php');

function getlist($p='',$search='',$by='1',$s='DESC') {
    $a = new PresetMessagesLookupAction();
    parse_str($search,$res);
    return $a->getlist($p,$res,$by,$s);
}
function lookup($what=''){
    $l = new PresetMessagesLookupAction();
    return $l->lookup($what);
}
function save($detail='',$id='',$action=''){
    $s = new PresetMessagesLookupAction();
    parse_str($detail,$res);
    return $s->save($res,$id,$action);
}

sajax_init();
//$sajax_debug_mode = 1;
sajax_export('getlist');
//sajax_export('lookup');
sajax_export('save');
sajax_handle_client_request();
$sajax_request_type = 'POST';
require('header_nomenu.php');
?>
<script language="JavaScript" type="text/javascript">

<?php sajax_show_javascript();?>

var s = "ASC";
var b = 1;

function page(p) {
    st = $('form1').toQueryString();
    load();
    x_getlist(p,st,b,s,getlist_cb)
}
function sort(by){
    s = (s=="DESC") ? "ASC" : "DESC";
    st = $('form1').toQueryString();
    p = $('pagenum');
    p = (p) ? p.value : 1;
    b = by;
    load();
    x_getlist(p,st,b,s,getlist_cb)
}
function filter(){
    st = $('form1').toQueryString();
    p = 1
    //st = Json.toString(st);
    load();
    x_getlist(p,st,b,s,getlist_cb);
}
function getlist_cb (new_data){
    //alert(new_data)
    data = Json_eval(new_data);
    var fields = [ ["id","ID"],
                   ["name","Preset Message"]

                 ]
    var  extra = [ [true,'id','edit'],
                   [false,'id','del']
                 ]

    $("thetable").innerHTML = data[1]
    $("thetable").innerHTML += mytable(data[0],fields, extra)
}

function levels_cb (new_data){
    data = Json_eval(new_data);
    AddToOptionList(data, $('school_year_id'), 'id','name')
}
function save () {
    data = $('form2').toQueryString();
    id = $('myid').value
    $('myid').value = ''
    x_save(data,id, function(new_data1){
      Json_eval(new_data1);
      filter();
      show_t()
    });
}
function show_t(){
    if($('thetable').style.display == "none"){
        hide_t('newform','thetable')
        $('altfrm').value = "New PresetMessagesLookup"
    } else {
        hide_t('thetable','newform')
        $('altfrm').value = "Back to List"
    }
    $('form2').reset();
}

function edit (id) {
	load();
	preset_message = opener.document.getElementById('preset_message');
	presetmsg_id = opener.document.getElementById('presetmsg');
    x_save('',id,'get', function(new_data1){
		d = Json_eval(new_data1)
		if (preset_message) preset_message.value = d['name'];
		if (presetmsg_id) presetmsg_id.value = d['id'];
		self.close();
    })
    return false;
}

function del (id) {
    if (confirm('Are you sure you want to delete this Record?')){
      x_save('',id,'del', function(new_data1){
        Json_eval(new_data1);
        filter();
      })
    }
}

function load (){
    $("thetable").innerHTML = loading;
}

</script>
<link rel="stylesheet" href="<?=WEB_MODULE_DIR?>css/structure2.css" type="text/css" />
<link rel="stylesheet" href="<?=WEB_MODULE_DIR?>css/form2.css" type="text/css" />
<!--<link rel="stylesheet" href="<?=WEB_MODULE_DIR?>css/theme2.css" type="text/css" />-->

<div align="center" class="centermain">
    <div class="main">
        <table class="adminheading">
            <tr>
                <th class="cpanel" rowspan="2" nowrap>PresetMessagesLookup &nbsp;<font size="1px" color="#CCCCCC">[<?=strtoupper($auth['privilege'])?>]</font></th>
            </tr>
        </table>
    </div>
        <table class="adminlist">
          <tr>
            <th class="title"><a href="javascript: show_tool('panel');">:: SEARCH PANEL</a></th>
          </tr>
          <tr>
            <td width="40%" valign="top">
            <!-- filter panel -->
          <div id="panel">
            <table class="adminlist">
              <tr>
                <td>
              <form id="form1" class="wufo" action="" method="post" onSubmit="filter();return false;">
                <ul>
                  <li>
                    <span>
                      <select class="field select" style="width:10em" name="search[searchfield]">
                            <option value="employee_no">Employee No.</option>
                            <option value="firstname">First Name</option>
                            <option value="lastname">Last Name</option>
                       </select>
                                </span>

                                <span>
                                  <input class="field text" size="15" name="search[searchtext]" value="" onKeyup="if (validSearch(this.value)) filter()" />
                                </span>

                                <span>
                                  <input id="saveForm" class="btTxt" type="button" value="Search" onClick="filter()"/>
                                  <input class="btTxt" type="button" value="Clear" onClick="this.form.reset();filter()"/>
                                </span>
                              </li>
                            </ul>
                          </form>
            </td>
              </tr>
            </table>
          </div>
            <!-- filter panel end -->
        </td>
        </tr>
    </table>
        <table class="adminform">
            <tr>
                <th class="title">:: SEARCH RESULTS</th>
            </tr>
            <tr>
              <td>
                      <div id="thetable">
                        <img src="/mcs/modpub/images/loading_small.gif"/>
                      </div>
              </td>
        </tr>
        </table>
<br/>
<div class="subuttons">
<input name="btnClose" onclick="window.close();" type="button" value="Close" style="float:right;">
</div>     
<script type="text/javascript">
//x_getlist(getlist_cb)
//x_lookup("school_year",levels_cb)
</script>

<?php require_once('footer.php'); ?>
